home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / desktop / att32all.zip / ATTSUPP.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-16  |  4KB  |  172 lines

  1. {$C FIXED PRELOAD PERMANENT}
  2. {R-,D-,X+}
  3.  
  4. Library AttSupp;
  5.  
  6. Uses WinTypes, WinProcs;
  7. Const
  8.     HookInUse           : boolean = false;         { true if hooks are set }
  9.     CallWndProcHookProc : tfarproc = nil;
  10.     gReceived : WordBool = False;
  11.     gJobs : Word = 0;
  12.     gJobStatus : Word = 0;
  13.  
  14.  
  15. Var
  16.     SaveExit : Pointer;
  17.     PrevMsgHook : TFarProc;
  18.     gHwnd : Hwnd;
  19.     gCommand : Word;
  20.     gWindow : Hwnd;
  21.  
  22. { ------------ }
  23. type
  24.   TCallData = record      { message record as passed to CallWndProc hook }
  25.     lParam : longint;
  26.     wParam : word;
  27.     Msg    : integer;
  28.     Hwnd   : hwnd;
  29.   end;
  30.  
  31. {-- Function Declarations -----------------------------------------------}
  32.  
  33. function CallWndProcHook(    nCode    : integer;
  34.                              wParam   : word;
  35.                          var CallData : TCallData) : longint; export;
  36. {
  37.   This is a hook to intercept messages passed by the SendMessage API call
  38.   before they are processed by an application.  This function sees all
  39.   such messages, but we only want left button clicks.  When we get one, we
  40.   post an AppMsg message to the window specified by AppHandle.
  41.  
  42.   AppHandle and AppMsg are initialized by a call to SetTheHook.
  43. }
  44.   begin
  45.     { REQUIRED }
  46.     if nCode < 0 then begin
  47.       CallWndProcHook := DefHookProc(ncode,wParam,longint(addr(CallData)),addr(CallWndProcHookProc));
  48.       exit;
  49.     end;
  50.  
  51.     { YOUR CODE GOES HERE }
  52.     (*
  53.     if (CallData.Msg = wm_LButtonDown) and (AppHandle <> 0) then
  54.       PostMessage(AppHandle,AppMsg,0,0);
  55.     *)
  56.  
  57.     If (CallData.Msg = wm_Command) then
  58.           Begin
  59.           gReceived := True;
  60.           gHwnd := CallData.hwnd;
  61.           gCommand := CallData.wParam;
  62.           End;
  63.     If (CallData.Msg = wm_SpoolerStatus) then
  64.           Begin
  65.           gJobSTatus := CallData.wParam;
  66.           gJobS := CallData.lParam and $ffff;
  67.           End;
  68.  
  69.  
  70.     { REQUIRED }
  71.     if CallWndProcHookProc <> nil then
  72.       CallWndProcHook := DefHookProc(ncode,wParam,longint(addr(CallData)),addr(CallWndProcHookProc))
  73.     else
  74.       CallWndProcHook := 0;
  75.   end { CallWndProcHook };
  76.  
  77. procedure UnsetTheHook; export;
  78. {
  79.   Unhook the hooks, but only if they're already set.
  80. }
  81.   begin
  82.     if (HookInUse) then begin
  83.       HookInUse := false;
  84.       UnhookWindowsHook(wh_CallWndProc,addr(CallWndProcHook));
  85.       CallWndProcHookProc := nil;
  86.     end;
  87.   end { UnsetTheHook };
  88. { ------------ }
  89.  
  90.  
  91. Procedure LibExit; export;
  92.     Begin
  93.     UnSetTheHook;
  94.     ExitProc := SaveExit;
  95.     End;
  96.  
  97. function SetTheHook : boolean; export;
  98. {
  99.   Sets the GetMessage and CallWndProc hooks.  Also sets up these two
  100.   variables:
  101.  
  102.     AppHandle  The handle of the app that needs to be notified when
  103.                a message is received.
  104.  
  105.     AppMsg     The message to send to NewAppHandle when a message
  106.                is received.
  107.  
  108.   If the hooks are already set (as indicated by HookInUse) then no hooks
  109.   are set and this function returns false.  We also check for appropriate
  110.   values for NewAppHandle and NewAppMsg before setting the hooks.
  111. }
  112.   begin
  113.     SetTheHook := false;
  114.     if (HookInUse) then exit;
  115.     SaveExit := ExitProc;
  116.     ExitProc := @LibExit;
  117.     CallWndProcHookProc := SetWindowsHook(wh_CallWndProc,addr(CallWndProcHook));
  118.     HookInUse := true;
  119.     SetTheHook := true;
  120.   end { SetTheHook };
  121.  
  122. Function wndEnumProc (AnHWnd :HWnd; lParam : LongInt) : Boolean; export;
  123. Begin
  124. While AnHwnd <> 0
  125.  do
  126.    Begin
  127.    gWindow := AnHWnd;
  128.    AnHWnd := GetParent(AnHwnd);
  129.    End;
  130. wndEnumProc := False;
  131. End;
  132.  
  133. Function TaskWindow (hTask :Word): HWND; export;
  134. Begin
  135.    TaskWindow := 0;
  136.    If EnumTaskWindows (hTask, @wndEnumProc, 0) then ;
  137.    TaskWindow := gWindow;
  138. End;
  139.  
  140. Function MessageReceived : LongInt; export;
  141.     Begin
  142.     If not gReceived then
  143.        MessageReceived := 0
  144.     Else
  145.        MessageReceived := ghWnd * 65536 + gCommand;
  146.  
  147.     gReceived := False;
  148.     End;
  149.  
  150. Function PrinterJobs : Word; export;
  151.     Begin
  152.     PrinterJobs := gJobs;
  153.     End;
  154.  
  155. Function PrinterStatus : Word; export;
  156.     Begin
  157.     PrinterStatus := gJobstatus;
  158.     End;
  159.  
  160.  
  161. Exports
  162.     wndEnumProc index 3,
  163.     TaskWindow index 4,
  164.     MessageReceived index 5,
  165.     PrinterJobs index 6,
  166.     PrinterStatus index 7,
  167.     SetTheHook   index 8,
  168.     UnsetTheHook index 9;
  169.  
  170. Begin
  171. End.
  172.